//
//  FXTMineViewController.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTMineViewController.h"
#import "FXTMineHeaderView.h"
#import "FXTSectionView.h"
#import "LoginViewController.h"
#import "FXTNavViewController.h"
#import "EditInformationViewController.h"
#import "managementViewController.h"
#import "companyDetailsViewController.h"
#import "certificationViewController.h"
#import "AboutusViewController.h"
#import "SetupViewController.h"
#import "AllOrdersViewController.h"
#define mineHeaderViewHeight   300
@interface FXTMineViewController ()<FXTSectionViewDelegate,FXTMineHeaderViewDelegate>
@property (nonatomic,strong)UIScrollView * backScrollView;
@property (nonatomic,strong)FXTMineHeaderView * mineHeaderView;
@property (nonatomic,strong)FXTUserModel * userModel;
@end

@implementation FXTMineViewController


-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    [super viewWillAppear:animated];
    self.userModel = [[FXTUserModel alloc] init];
    self.userModel.token = @"a6333fdfdbaa8800130c39c5bedc6b66";
    if (self.userModel.token) {
        [self getUserInfo];
    }
    
}
-(void)viewWillDisappear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}


- (void)viewDidLoad {
    self.title = @"";
    [super viewDidLoad];
   
    // Do any additional setup after loading the view.
    [self.view addSubview:self.backScrollView];
    [self.backScrollView addSubview:self.mineHeaderView];
    NSArray * imageArray = @[@"icon_qbdd",@"icon_guanlizhongxin",@"icon_yjtj",@"icon_woderenzheng",@"icon_qlhc",@"icon_szzx",@"icon_bzzx",@"icon_kfzx",@"icon_gywm"];
    NSArray * titleArray = @[@"全部订单",@"管理中心",@"有奖推荐",@"我的认证",@"清除缓存",@"设置中心",@"帮助中心",@"客服中心",@"关于我们"];
    NSArray * infoArray = @[@"已接订单、已发布订单",@"个人管理、企业信息",@"推荐码、推荐奖励",@"实名认证、企业认证",@"清除缓存、运行更快",@"设置修改登录密码",@"理赔说明、发布流程",@"努力为您解决问题",@"意见反馈、平台信息"];
    CGFloat  spacing = 1.0f;
    int j = 0;
    int k = 0;
    CGFloat  orignY = CGRectGetMaxY(self.mineHeaderView.frame);
    for (int i = 0; i <infoArray.count; i++) {
        FXTSectionView * sectionView = [[FXTSectionView alloc] initWithFrame:CGRectMake(k*(SCREEN_WIDTH/2+spacing), orignY+j*100+spacing, SCREEN_WIDTH/2-spacing, 100)];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.sectionInfo = infoArray[i];
        sectionView.sectionTitle = titleArray[i];
        sectionView.sectionHeader = imageArray[i];
        sectionView.tag=100+i;
        sectionView.layer.borderColor = RGBCOLOR(214, 215, 216).CGColor;
        sectionView.layer.borderWidth = 0.5f;
        
        UITapGestureRecognizer* singleRecognizer;
        singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ShouShiTuianPian:)];
        singleRecognizer.numberOfTapsRequired = 1; 

        [sectionView addGestureRecognizer:singleRecognizer];
        
        
        
        [self.backScrollView addSubview:sectionView];
        
        
        
        
        
        
               k++;
        if (k>=2) {
            j++;
            k = 0;
        }
        self.backScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, CGRectGetMaxY(sectionView.frame)+20);
    }
    
     [self initNav];
}

- (void)ShouShiTuianPian:(UITapGestureRecognizer *)ShouShi{
    if (ShouShi.view.tag==100) {
      
        AllOrdersViewController*EditInformationVC=[[AllOrdersViewController alloc]init];
        [self .navigationController pushViewController:EditInformationVC animated:YES];
        
    }else    if (ShouShi.view.tag==101) {
        managementViewController*EditInformationVC=[[managementViewController alloc]init];
        [self .navigationController pushViewController:EditInformationVC animated:YES];
    
    }else if (ShouShi.view.tag==103) {
        
        certificationViewController*companyDetailsVC=[[certificationViewController alloc]init];
        [self .navigationController pushViewController:companyDetailsVC animated:YES];
   
        
    }else if (ShouShi.view.tag==105){
        SetupViewController*companyDetailsVC=[[SetupViewController alloc]init];
        [self .navigationController pushViewController:companyDetailsVC animated:YES];
    }
    
    
    else if (ShouShi.view.tag==108){
    
        AboutusViewController*companyDetailsVC=[[AboutusViewController alloc]init];
        [self .navigationController pushViewController:companyDetailsVC animated:YES];
    }
}
-(FXTNavType)getNavType {
    return FXTNavTypeNone;
}



-(void)initNav{
    UIButton *  tempBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [tempBtn setAdjustsImageWhenHighlighted:NO];
    tempBtn.frame = CGRectMake(280*kAppScale, 30*kAppScale, 80*kAppScale, 44*kAppScale);
    tempBtn.titleLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:16.0f];
    [tempBtn setTitle:@"个人资料" forState:UIControlStateNormal];
    [tempBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [tempBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tempBtn addTarget:self action:@selector(registerUsers) forControlEvents:UIControlEventTouchUpInside];
    [_backScrollView addSubview:tempBtn];
    
//    [_mineHeaderView bringSubviewToFront:tempBtn];
}
- (void)registerUsers{
    EditInformationViewController*EditInformationVC=[[EditInformationViewController alloc]init];
    [self .navigationController pushViewController:EditInformationVC animated:YES];

}

# pragma - Request
// 获取我的信息
-(void)getUserInfo{
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_GET;
    requestModel.appendUrl = kUser_my;
    NSMutableDictionary * paramDic = [NSMutableDictionary dictionary];
    [paramDic setValue:self.userModel.token forKey:@"token"];
    
    WS(ws);
    requestModel.paramDic = paramDic;
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error  ){
        if (result.state ==FXTReponseCodeState_Success) {
            NSLog(@"wswswsws%@",result.data);
          
            
        ws.userModel = [FXTUserModel dicWithUserAccount:result.data];
        ws.mineHeaderView.userModel = ws.userModel;
        }else {
        [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
}

# pragma -  FXTMineHeaderViewDelegate

-(void)alertPersonView{

    LoginViewController*li=[[LoginViewController  alloc]init];
    [self.navigationController pushViewController:li animated:YES];
    

}
- (void)touchThreeButton:(NSInteger)tag{
    DDLog(@"111%ld",(long)tag);
    if (tag==0) {
//        companyDetailsViewController*companyDetailsVC=[[companyDetailsViewController alloc]init];
//        [self .navigationController pushViewController:companyDetailsVC animated:YES];
    }else if (tag==1){
    

    }

}

# pragma -  FXTSectionViewDelegate
- (void)chooseSection:(NSInteger)tag{
    DDLog(@"%ld",(long)tag);
}

# pragma -  Setter  &  Getter
-(FXTUserModel *)userModel{
    if (!_userModel) {
        _userModel = [FXTUserTools UserAccount];
    }return _userModel;
}
-(UIScrollView *)backScrollView{
    if (!_backScrollView) {
        _backScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationBar_HEIGHT)];
        _backScrollView.backgroundColor = [UIColor whiteColor];
    }return _backScrollView;
}
-(FXTMineHeaderView *)mineHeaderView{
    if (!_mineHeaderView) {
        _mineHeaderView = [[FXTMineHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, mineHeaderViewHeight)];
        _mineHeaderView.delegate = self;
        _mineHeaderView.backgroundColor =  [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon_bjj"]];
    }
    return _mineHeaderView;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
